package com.syq.service.impl;

import com.syq.constant.CacheConstants;
import com.syq.constant.StrategyConstants;
import com.syq.feign.CacheFeign;
import com.syq.model.StandardSubmit;
import com.syq.service.FilterChainService;
import com.syq.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @ClassName: BlackFilterServiceImpl
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/8/27 9:48
 */

@Service("black")
@Slf4j
public class BlackFilterServiceImpl implements FilterChainService {

    @Autowired
    private CacheFeign cacheFeign;

    @Autowired
    private PushMsgUtil pushMsgUtil;

    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        System.out.println("执行黑名单");
        String destMobile = standardSubmit.getDestMobile();
        String key= CacheConstants.CACHE_PREFIX_BLACK+destMobile;
        String s = cacheFeign.get(key);
        if (StringUtils.isEmpty(s)&&"1".equals(s)){
            pushMsgUtil.sendLog(standardSubmit, StrategyConstants.STRATEGY_ERROR_BLACK);
            pushMsgUtil.pushReport(standardSubmit,StrategyConstants.STRATEGY_ERROR_BLACK);
            log.error("策略模块-[黑名单策略]:有此"+destMobile);
            return false;
        }
        return true;
    }
}
